package servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import bean.OficinaDeVentaVO;
import cliente.BDelegate;

/**
 * Servlet implementation class VerOficinas
 */
public class VerOficinas extends HttpServlet implements Servlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public VerOficinas() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		@SuppressWarnings("unused")
		HttpSession session = request.getSession();

		PrintWriter out = response.getWriter();
		BDelegate bd = new BDelegate();

		List<OficinaDeVentaVO> oficinasDeVenta = bd.obtenerOficinas();

		System.out.println("" + "oficina:" + oficinasDeVenta.get(0).getDescripcion().toString());
		// RequestDispatcher dispatcher = getServletContext().
		// getRequestDispatcher("/LogOficinas.jsp");
		// leite auf die JSP Datei zum Anzeigen der Liste weiter
		// dispatcher.forward(request, response);

		response.setContentType("text/html");

		out.write("<ul>");
		for (int i = 0; i < oficinasDeVenta.size(); i++) {
			out.write("<li>");
			out.write(oficinasDeVenta.get(i).getDescripcion().toString());
			out.write("</li>");
		}
		out.write("</ul>");

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.doGet(request, response);

	}

}
